package com.pic.mgt.monitor.parser.haishin;

import com.pic.mgt.monitor.WrongUnitFormatException;
import com.pic.mgt.monitor.parser.FormatParser;

public final class HaishinMessageBusinessTypeParser extends FormatParser {
	private int messageBusinessTypeAtChar;

	@Override
	public Object parse(Object _messageConfirmationFilename) throws WrongUnitFormatException {
		super.checkObjectType(_messageConfirmationFilename, String.class);
		
		String messageConfirmationFilename = (String)_messageConfirmationFilename;
		
		try {
			String messageIgxType =
					String.valueOf(messageConfirmationFilename.charAt(messageBusinessTypeAtChar - 1));
			
			return messageIgxType;
		} catch (IndexOutOfBoundsException e) {
			throw new WrongUnitFormatException(
					"The confirmation filename '" + messageConfirmationFilename +
					"' of message is not correct!");
		}
	}
	
	// --- getter and setter ---

	public void setMessageBusinessTypeAtChar(int messageBusinessTypeAtChar) {
		this.messageBusinessTypeAtChar = messageBusinessTypeAtChar;
	}

}
